package com.api.server.service.impl;

import com.api.server.pojo.Maintain;
import com.api.server.pojo.Order;
import com.api.server.mapper.OrderMapper;
import com.api.server.pojo.User;
import com.api.server.pojo.UserListPage;
import com.api.server.service.IOrderService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author shi
 * @since 2022-04-28
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public Order message(String ordernumber) {

        return orderMapper.selectById(ordernumber);
    }

    @Override
    public int add(Order order) {
        order.setOrderstatus("待处理");
        order.setState("true");
        return orderMapper.insert(order);
    }

    @Override
    public Map<String, Object> page(UserListPage userListPage) {
        Page pageInfo = new Page(userListPage.getPagenum(),userListPage.getPagesize());
        IPage<User> iPage = orderMapper.selectPage(pageInfo,new QueryWrapper<Order>().lambda().like(Order::getOrderfacilities,userListPage.getQuery()).or().like(Order::getOrdervenue,userListPage.getQuery()).or().like(Order::getOrderstatus,userListPage.getQuery()).or().like(Order::getOrderid,userListPage.getQuery()).or().like(Order::getState,userListPage.getQuery()));
        Map<String,Object> pageMap = new HashMap<>(3);
        //总条数
        pageMap.put("total",iPage.getTotal());
        //总页数
        pageMap.put("pages",iPage.getPages());
        //当前页码
        pageMap.put("pagenum",iPage.getSize());
        //数据集合
        pageMap.put("current_data",iPage.getRecords());

        return pageMap;
    }
}
